home *** CD-ROM | disk | FTP | other *** search
/ IRIX Patches 1995 March / SGI IRIX Patches 1995 Mar.iso / 5.2_patches / patchSG0000226 / patchSG0000226.idb / usr / include / sys / ktime.h.z / ktime.h
C/C++ Source or Header  |  1995-03-10  |  6KB  |  220 lines

  1. /**************************************************************************
  2.  *                                      *
  3.  *          Copyright (C) 1989-1992 Silicon Graphics, Inc.          *
  4.  *                                      *
  5.  *  These coded instructions, statements, and computer programs  contain  *
  6.  *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
  7.  *  are protected by Federal copyright law.  They  may  not be disclosed  *
  8.  *  to  third  parties  or copied or duplicated in any form, in whole or  *
  9.  *  in part, without the prior written consent of Silicon Graphics, Inc.  *
  10.  *                                      *
  11.  **************************************************************************/
  12. #ifndef _SYS_KTIME_H
  13. #define _SYS_KTIME_H
  14.  
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18.  
  19. /*
  20.  * This header contains internal kernel time handling data structures
  21.  * Do not use __mips macro here
  22.  * Use ONLY definitions that are constant whether compiled mips2 or 3
  23.  */
  24.  
  25. /*
  26.  * IRIX4 versions of time interface structures
  27.  *
  28.  * IRIX4 and 5 timevals and itimervals are the same
  29.  * IRIX4 has no timestruc
  30.  */
  31.  
  32. /*
  33.  * IRIX5/Mips ABI versions of time interface structures
  34.  */
  35. typedef struct irix5_timestruc {
  36.     app32_long_t tv_sec;
  37.     app32_long_t tv_nsec;
  38. } irix5_timestruc_t;
  39.  
  40. struct irix5_timeval {
  41.     app32_long_t    tv_sec;        /* seconds */
  42.     app32_long_t    tv_usec;    /* and microseconds */
  43. };
  44.  
  45. struct irix5_itimerval {
  46.     struct    irix5_timeval it_interval;    /* timer interval */
  47.     struct    irix5_timeval it_value;    /* current value */
  48. };
  49.  
  50. #define timestruc_to_irix5(t,i5)    \
  51.             (i5)->tv_sec = (t)->tv_sec; \
  52.             (i5)->tv_nsec = (t)->tv_nsec;
  53.  
  54. #define timeval_to_irix5(t,i5)    \
  55.             (i5)->tv_sec = (t)->tv_sec; \
  56.             (i5)->tv_usec = (t)->tv_usec;
  57.  
  58. #define irix5_to_timeval(t,i5)    \
  59.             (t)->tv_sec = (i5)->tv_sec; \
  60.             (t)->tv_usec = (i5)->tv_usec;
  61.  
  62. typedef app32_long_t    irix5_time_t;
  63.  
  64. /*
  65.  * IRIX5_64 versions of time interface structures
  66.  */
  67. typedef struct irix5_64_timestruc {
  68.     app64_long_t tv_sec;
  69.     app64_long_t tv_nsec;
  70. } irix5_64_timestruc_t;
  71.  
  72. struct irix5_64_timeval {
  73.     app64_long_t    tv_sec;        /* seconds */
  74.     app64_long_t    tv_usec;    /* and microseconds */
  75. };
  76.  
  77. struct irix5_64_itimerval {
  78.     struct    irix5_64_timeval it_interval;    /* timer interval */
  79.     struct    irix5_64_timeval it_value;    /* current value */
  80. };
  81.  
  82. #define timestruc_to_irix5_64(t,i5_64)    \
  83.             (i5_64)->tv_sec = (t)->tv_sec; \
  84.             (i5_64)->tv_nsec = (t)->tv_nsec;
  85.  
  86. #define timeval_to_irix5_64(t,i5_64)    \
  87.             (i5_64)->tv_sec = (t)->tv_sec; \
  88.             (i5_64)->tv_usec = (t)->tv_usec;
  89.  
  90. typedef app64_long_t    irix5_64_time_t;
  91.  
  92. /*
  93.  * Internal kernel versions of time structures
  94.  * Kernel should use the irix* structures for system call interfaceing
  95.  * Kernel uses the user definitions of timestruc, timeval and itimerval
  96.  *    internally - these will change size in 64 bit mode but that
  97.  *    shouldn't matter (but proc and user will chg size!)
  98.  */
  99. #ifdef NOTUSED
  100. typedef struct ktimestruc {
  101.     __int32_t tv_sec;
  102.     __int32_t tv_nsec;
  103. } ktimestruc_t;
  104.  
  105. struct ktimeval {
  106.     __int32_t    tv_sec;        /* seconds */
  107.     __int32_t    tv_usec;    /* and microseconds */
  108. };
  109.  
  110. struct kitimerval {
  111.     struct    ktimeval it_interval;    /* timer interval */
  112.     struct    ktimeval it_value;    /* current value */
  113. };
  114. #endif
  115.  
  116. #define    USEC_PER_SEC    1000000        /* number of usecs for 1 second    */
  117. #define    NSEC_PER_SEC    1000000000    /* number of nsecs for 1 second    */
  118. #define USEC_PER_TICK    (USEC_PER_SEC/HZ)
  119. #define NSEC_PER_TICK    (NSEC_PER_SEC/HZ)
  120.  
  121. /* has to be rt process, plus not multiple of 10ms */
  122. #define need_fastimer(tvp, pp)    ((pp->p_rtpri >= NDPHIMAX && \
  123.                    pp->p_rtpri <= ndpri_lolim) && \
  124.                  (tvp)->tv_usec != 0 && \
  125.                  ( ((tvp)->tv_usec < USEC_PER_TICK) || \
  126.                    ((tvp)->tv_usec % USEC_PER_TICK) != 0 ))
  127.  
  128. /*
  129.  * Macro to round usec to sec in time timeval structure.
  130.  * We even go so far as to loop decrementing usec and adding to
  131.  * seconds until usec < sec.
  132.  */
  133. #define    RNDTIMVAL(t) \
  134.     { \
  135.         register struct timeval *tp = (t); \
  136.         \
  137.         while ( tp->tv_usec >= USEC_PER_SEC ) \
  138.         { \
  139.             tp->tv_usec -= USEC_PER_SEC; \
  140.             tp->tv_sec++; \
  141.         } \
  142.     }
  143.  
  144. #define    RND_TIMESTRUC_VAL(t) \
  145.     { \
  146.         register timestruc_t *tp = (t); \
  147.         \
  148.         while ( tp->tv_nsec >= NSEC_PER_SEC ) \
  149.         { \
  150.             tp->tv_nsec -= NSEC_PER_SEC; \
  151.             tp->tv_sec++; \
  152.         } \
  153.     }
  154.  
  155. /*
  156.  * macros to convert from timestruc to timeval and vice-versa
  157.  */
  158. #define TIMESTRUC_TO_TIMEVAL(ts, tv)    \
  159.     { \
  160.         (tv)->tv_sec = (ts)->tv_sec; \
  161.         (tv)->tv_usec = (ts)->tv_nsec/1000; \
  162.     }
  163. #define TIMEVAL_TO_TIMESTRUC(tv, ts)    \
  164.     { \
  165.         (ts)->tv_sec = (tv)->tv_sec; \
  166.         (ts)->tv_nsec = (tv)->tv_usec*1000; \
  167.     }
  168.  
  169. struct proc;
  170. struct eframe_s;
  171. struct rusage;
  172.  
  173. struct timestruc;
  174. struct timeval;
  175. extern void realitexpire(struct proc *);
  176. extern void ticks_to_nanosecs(time_t, struct timestruc *);
  177. extern long doadjtime(long);
  178. extern void nanotime(struct timestruc *);
  179. extern void microtime(struct timeval *);
  180. extern void tick_to_timeval(int, struct timeval *, int);
  181. extern time_t fasthzto(struct timeval *);
  182. extern time_t hzto(struct timeval *);
  183. extern time_t timestruc_to_ticks(struct timestruc *);
  184. extern void timevalfix(struct timeval *);
  185. extern void timevalsub(struct timeval *, struct timeval *);
  186. extern void timevaladd(struct timeval *, struct timeval *);
  187. extern int itimerfix(struct timeval *);
  188. extern int itimerdecr(register struct itimerval *, int);
  189. extern void timestruc_add(struct timestruc *, struct timestruc *);
  190. extern void timestruc_fix(struct timestruc *);
  191. extern __psint_t query_cyclecntr(uint *);
  192. extern int    chktimeout_tick(int, void (*)(), void *);
  193. extern void    ackrtclock(void);
  194. extern void    bump_leds(void);
  195. extern int    loclkok(struct eframe_s *);
  196. extern int    set_timer_intr(processorid_t, long);
  197. extern void    settime(long, long);
  198. extern void    wtodc(void);
  199. extern void    ru_timecal(struct proc *, struct rusage *);
  200. extern void    enable_fastclock(void);
  201. extern int    dosetitimer(int, struct itimerval *, struct itimerval *);
  202. extern time_t    get_realtime_ticks(void);
  203. extern int    callout_time_to_hz(int, int);
  204. extern int    settimetrim(int);
  205. extern int    gettimetrim(void);
  206.  
  207. #if _K64U64
  208. enum xlate_mode;
  209. struct xlate_info_s;
  210. extern int irix5_to_timeval_xlate(enum xlate_mode, void *,
  211.                   int, struct xlate_info_s *);
  212. extern int timeval_to_irix5_xlate(void *, int, struct xlate_info_s *);
  213. #endif
  214.  
  215. #ifdef __cplusplus
  216. }
  217. #endif
  218.  
  219. #endif /* _SYS_KTIME_H */
  220.